﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MeTV.MediaPortalService;

namespace MeTV
{
    class ScheduleManager
    {
        WebSchedule[] schedules = null;
        public static ScheduleManager Instance = new ScheduleManager();

        public void Load()
        {
            schedules = Client.Instance.client.GetAllSchedules();
        }

        public bool IsScheduled(WebProgram program)
        {
            return IsScheduled(program.idChannel, program.startTime, program.endTime);
        }

        public bool IsScheduled(Channel channel, DateTime startTime, DateTime endTime)
        {
            return IsScheduled(channel.ID, startTime, endTime);
        }

        public bool IsScheduled(int channelID, DateTime startTime, DateTime endTime)
        {
            return schedules == null || schedules.Count(x => x.idChannel == channelID && x.startTime <= startTime && x.endTime >= endTime) > 0;
        }

        public WebSchedule[] GetSchedules(WebProgram program)
        {
            return schedules.Where(x => x.idChannel == program.idChannel && x.startTime <= program.startTime && x.endTime >= program.endTime).ToArray();
        }
    }
}
